#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>

int main() {
    std::vector<std::string> num = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::vector<int> prime;
    std::string input;
    std::getline(std::cin, input);
    std::vector<std::string> a;
    
    size_t pos = 0;
    std::string token;
    while ((pos = input.find(' ')) != std::string::npos) {
        token = input.substr(0, pos);
        a.push_back(token);
        input.erase(0, pos + 1);
    }
    a.push_back(input);

    for (int p = 2; p < 1500; ++p) {
        bool pr = true;
        for (int i = 2; i <= static_cast<int>(std::sqrt(p)) + 1; ++i) {
            if (p % i == 0) {
                pr = false;
                break;
            }
        }
        if (pr) {
            prime.push_back(p);
        }
    }

    int f = 0;
    for (const auto& i : a) {
        if (std::find(num.begin(), num.end(), i) == num.end()) {
            f = 1;
            break;
        }
    }

    if (f == 1 || a.size() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        std::string b = "";
        for (const auto& i : a) {
            b += std::to_string(std::distance(num.begin(), std::find(num.begin(), num.end(), i)));
        }
        int num_b = std::stoi(b);
        if (std::find(prime.begin(), prime.end(), num_b) != prime.end()) {
            std::cout << num_b << std::endl;
        } else {
            int bl = 10000000000;
            for (const auto& i : prime) {
                if (std::abs(num_b - i) < std::abs(num_b - bl)) {
                    bl = i;
                }
            }
            std::cout << bl << std::endl;
        }
    }

    return 0;
}
